
<template >
    <div>
        <modaltemplate :tzcount="tzcount" :ctcount="ctcount" :areaflag='areaflag'>
            <template v-slot:changtai="slotProps">
                <commonbox :getRegion='getRegion' :getSensor='getSensor' :itemlists="data[slotProps.menuitem]" />
            </template>

            <template v-slot:pie="slotProps">
                <pie v-if="showPie" :dataitems="dataitems" />
            </template>

            <template v-slot:form="slotProps">
                <forms class="right-b" :fromsData="fromsData"></forms>
            </template>
        </modaltemplate>
    </div>
</template>
<script lang="ts">
import modaltemplate from '@/components/modal.vue'
import commonbox from '@/components/commonbox.vue'
import pie from '@/components/pie.vue'
import { ref, reactive } from 'vue-demi'
import forms from '@/components/forms.vue'
import {
    getRunState,
    getCitySignNumber,
    getHomePageCitySign,
    getCitySign,
    getCaseNumberByType,
    getCaseList,
    getRegion,
    getSensor,
} from '../api/YangPu'

export default {
    name: 'yangpu',
    components: {
        modaltemplate,
        commonbox,
        pie,
        forms,
    },
    props: {
        menuitem: Array,
    },
    setup(props) {
        // 运行状态
        let areaflag = ref('')
        getRunState().then((state) => {
            areaflag.value = state
        })

        // 获得今天体征项目的数据接口
        let ctcount = reactive({ num: 0 })
        getCitySignNumber().then((num) => {
            ctcount.num = num
        })

        // 通过type获得对应的三级指标项目的名称以及值
        let data = reactive({
            chengshizhisheng: [],
            chengshizhigan: [],
            chengshizhiyan: [],
            chengshihuxi: [],
            chengshiwendu: [],
            chengshimaibo: [],
        })
        let types = {
            chengshizhisheng: 1,
            chengshizhigan: 2,
            chengshizhiyan: 3,
            chengshihuxi: 4,
            chengshiwendu: 5,
            chengshimaibo: 6,
        }
        for (let key in types) {
            let type = types[key]

            getCitySign(type).then((list) => {
                let childs = list[0]['child']
                // 二级child
                for (let childIndex in childs) {
                    var item = { title: '', items: [] }
                    let lastChild = childs[childIndex]['child']
                    item.title = childs[childIndex]['name']
                    // 弹窗类型
                    item.pop_type = childs[childIndex]['pop_type']
                        ? childs[childIndex]['pop_type']
                        : 0
                    item.id = childs[childIndex]['id']
                        ? childs[childIndex]['id']
                        : 0

                    // 三级child
                    if (lastChild != null) {
                        for (let lastIndex in lastChild) {
                            item['items'].push({
                                item: lastChild[lastIndex].name,
                                value: lastChild[lastIndex].value,
                                unit: lastChild[lastIndex].unit,
                            })
                        }
                    } else {
                        item['items'].push({
                            item: childs[childIndex].name,
                            value: childs[childIndex].value,
                            unit: childs[childIndex].unit,
                        })
                    }

                    data[key].push(item)
                }
            })
        }

        // 获得各类案件个数
        let showPie = ref(false)
        let tzcount = ref(0) //体征发现
        let dataitems = reactive([
            {
                name: '智联',
                value: 0,
                unit: '条',
            },
            {
                name: '主动',
                value: 0,
                unit: '条',
            },
            {
                name: '被动',
                value: 0,
                unit: '条',
            },
        ])
        getCaseNumberByType().then((data) => {
            if (data.passiveCaseNumber == 'pending') {
                dataitems[2].pending = true
            }

            tzcount.value = data.totalNumber
            dataitems[0].value = data.smartCaseNumber
            dataitems[1].value = data.activeCaseNumber
            dataitems[2].value =
                data.passiveCaseNumber == 'pending' ? 0 : data.passiveCaseNumber
            showPie.value = true
        })

        // 获得对应的案件列表
        let fromsData = ref([])
        let showForms = ref(false)
        getCaseList().then((list) => {
            let temp = []
            for (let i in list) {
                let type = list[i]['type']
                switch (type) {
                    case '1':
                        type = '主动'
                        break
                    case '2':
                        type = '被动'
                        break
                    case '3':
                        type = '智联'
                        break
                }

                temp.push({
                    time: list[i]['create_time'],
                    text: list[i]['content'],
                    address: list[i]['address'],
                    state: list[i]['case_status'],
                    type: type,
                })
            }

            fromsData.value = temp
            showForms.value = true
        })

        return {
            data,
            dataitems,
            showPie,
            fromsData: reactive(fromsData),
            tzcount,
            ctcount,
            areaflag,
            getRegion,
            getSensor,
        }
    },
}
</script>
<style lang="less" scoped>
</style>